/*

 Copyright (C) 2009-2011 Oleksandr Natalenko aka post-factum

 This program is free software; you can redistribute it and/or modify
 it under the terms of the Universal Program License as published by
 Oleksandr Natalenko aka post-factum; see file COPYING for details.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 You should have received a copy of the Universal Program
 License along with this program; if not, write to
 pfactum@gmail.com

*/

package modulation;

import core.AnalogSignal;

/**
 * Model of modulator signal
 *
 * @author Oleksandr Natalenko aka post-factum
 */
public class ModulatorSignal implements AnalogSignal {
    public double frequency;
    public double amplitude;
    public double phase;
    public double maxValue;
    public double minValue;
    public double xStart, xEnd;

    /**
     * Creates modulator signal
     *
     * @param _frequency frequency, Hz
     * @param _amplitude amplitude, V
     * @param _phase     phase, rad
     * @param _start     start time, s
     * @param _end       end time, s
     */
    public ModulatorSignal(double _frequency, double _amplitude, double _phase, double _start, double _end) {
        frequency = _frequency;
        amplitude = _amplitude;
        phase = _phase;
        maxValue = _amplitude;
        minValue = -_amplitude;
        xStart = _start;
        xEnd = _end;
    }


    /**
     * Returns f(x) for current signal
     *
     * @param _x time variable, s
     * @return real value of signal function in x point
     */
    @Override
    public double function(double _x) {
        return amplitude * Math.sin(2 * Math.PI * frequency * _x + phase);
    }


    /**
     * Returns Signal frequency, Hz
     *
     * @return real value of signal frequency
     */
    public double getFrequency() {
        return frequency;
    }

    /**
     * Sets signal frequency
     *
     * @param frequency signal frequency, Hz
     */
    public void setFrequency(double frequency) {
        this.frequency = frequency;
    }

    /**
     * Returns signal amplitude, V
     *
     * @return real value of signal amplitude
     */
    public double getAmplitude() {
        return amplitude;
    }

    /**
     * Sets signal amplitude, V
     *
     * @param amplitude signal amplitude, V
     */
    public void setAmplitude(double amplitude) {
        this.amplitude = amplitude;
    }

    /**
     * Returns signal phase
     *
     * @return real value of signal phase, rad
     */
    public double getPhase() {
        return phase;
    }

    /**
     * Sets signal phase
     *
     * @param phase signal phase, rad
     */
    public void setPhase(double phase) {
        this.phase = phase;
    }

    /**
     * Returns signal maximum value, V
     *
     * @return real maximum signal value
     */
    public double getMaxValue() {
        return maxValue;
    }

    /**
     * Returns signal minimum value, V
     *
     * @return real minimum signal value
     */
    public double getMinValue() {
        return minValue;
    }

    /**
     * Returns signal start point, s
     *
     * @return real signal start time
     */
    public double getStart() {
        return xStart;
    }

    /**
     * Sets signal starting point
     *
     * @param xStart signal start time, s
     */
    public void setStart(double xStart) {
        this.xStart = xStart;
    }

    /**
     * Returns signal end point, s
     *
     * @return real signal end time
     */
    public double getEnd() {
        return xEnd;
    }

    /**
     * Sets signal end time
     *
     * @param xEnd signal end time, s
     */
    public void setEnd(double xEnd) {
        this.xEnd = xEnd;
    }
}
